package org.corey.dev.voxiverse;

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

public class InputHandler {
	static float dx = 0.0f;
	static float dy = 0.0f;
	
	static float mouseSensitivity = 0.05f;
	float movementSpeed = 10.0f;
	
	static void ProcessInput() {
		
		dx = Mouse.getDX();
		dy = Mouse.getDY();
		
		Game.player.yaw(dx * mouseSensitivity);
		Game.player.pitch(dy * mouseSensitivity);
		
		//use (float) Math.sin(Math.toRadians(Game.player.yaw))
		//so that I can do directional directions based on
		//button pressed, then check which direction that 
		//is to check if a block is in the way
		
		if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
			if( Player.CanMove(Player.PlayerX,Player.PlayerY + 1,Player.PlayerZ)){
				//Player.PY--;
				Game.player.position.y--;
			}
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
			if( Player.CanMove(Player.PlayerX,Player.PlayerY - 1,Player.PlayerZ)){
				//Player.PY++;
				Game.player.position.y++;
			}
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
			if( Player.CanMove(Player.PlayerX - (1 * (float) Math.sin(Math.toRadians(Game.player.yaw+90))),Player.PlayerY,Player.PlayerZ + (1 * (float) Math.cos(Math.toRadians(Game.player.yaw-90))))){
				//Player.PX++;
				Game.player.position.x -= 1 * (float) Math.sin(Math.toRadians(Game.player.yaw-90));
				Game.player.position.z += 1 * (float) Math.cos(Math.toRadians(Game.player.yaw-90));
			}
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
			if( Player.CanMove(Player.PlayerX - (1 * (float) Math.sin(Math.toRadians(Game.player.yaw-90))),Player.PlayerY,Player.PlayerZ + (1 * (float) Math.cos(Math.toRadians(Game.player.yaw-90))))){
				//Player.PX--;
				Game.player.position.x -= 1 * (float) Math.sin(Math.toRadians(Game.player.yaw+90));
				Game.player.position.z += 1 * (float) Math.cos(Math.toRadians(Game.player.yaw+90));
			}
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
			if( Player.CanMove(Player.PlayerX - (1 * (float) Math.sin(Math.toRadians(Game.player.yaw))), Player.PlayerY, Player.PlayerZ + (1 * (float) Math.cos(Math.toRadians(Game.player.yaw))))){
				//Player.PZ--;
				Game.player.position.x += 1 * (float) Math.sin(Math.toRadians(Game.player.yaw));
				Game.player.position.z -= 1 * (float) Math.cos(Math.toRadians(Game.player.yaw));
			}
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
			if( Player.CanMove(Player.PlayerX + (1 * (float) Math.sin(Math.toRadians(Game.player.yaw))), Player.PlayerY, Player.PlayerZ - (1 * (float) Math.cos(Math.toRadians(Game.player.yaw))))){
				//Player.PZ++;
				Game.player.position.x -= 1 * (float) Math.sin(Math.toRadians(Game.player.yaw));
				Game.player.position.z += 1 * (float) Math.cos(Math.toRadians(Game.player.yaw));
			}
		}
		
		Player.filename = null;

	}
}
